import request from "@/utils/request";
import type {
  AddOrUpdateSkuParams,
  SkuList,
  GetSkuListApiResponse,
} from "./type/skuType";

const enum Api {
  addSku = "/admin/product/saveSkuInfo",
  getSkuListBySpuId = "/admin/product/findBySpuId",
  getSkuList = "/admin/product/list",
  cancelSale = "/admin/product/cancelSale",
  onSale = "/admin/product/onSale",
  getSkuById = "/admin/product/getSkuById",
}

// 添加sku
export const addSkuApi = (data: AddOrUpdateSkuParams) => {
  return request.post<any, null>(Api.addSku, data);
};

// 通过SpuId获取Sku列表
export const getSkuListBySpuIdApi = (spuId: number) => {
  return request.get<any, SkuList>(Api.getSkuListBySpuId + `/${spuId}`);
};

// 获取sku列表
export const getSkuListApi = (page: number, limit: number) => {
  return request.get<any, GetSkuListApiResponse>(
    Api.getSkuList + `/${page}/${limit}`
  );
};

// 下架
export const cancelSaleApi = (skuId: number) => {
  return request.get<any, null>(Api.cancelSale + `/${skuId}`);
};

// 上架
export const onSaleApi = (skuId: number) => {
  return request.get<any, null>(Api.onSale + `/${skuId}`);
};

// 获取sku详情
export const getSkuById = (skuId: number) => {
  return request.get<any, AddOrUpdateSkuParams>(Api.getSkuById + `/${skuId}`);
};
